//
//  TT_MediaBannerView.m
//  goodsDetailBannerDemo
//
//  Created by 王洋 on 2019/7/9.
//  Copyright © 2019 王洋. All rights reserved.
//

#import "TT_MediaBannerView.h"

@interface TT_MediaBannerView ()<SDCycleScrollViewDelegate>

@end

@implementation TT_MediaBannerView

- (instancetype)initWithType:(BOOL)isShowVideoView {
    self = [super init];
    if (self) {

        self.isShowVideoView = isShowVideoView;
        [self layout];
        
    }
    return self;
}

- (void)layout {
    
    [self addSubview:self.normalView];
    [self.normalView addSubview:self.avPlayer];
    [self addSubview:self.bannerView];
    
    if (self.isShowVideoView) {

        
        [self.normalView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.mas_equalTo(0);
            make.height.mas_equalTo(self);
            make.width.mas_equalTo(TTScreenWidth);
        }];
        
        [self.avPlayer mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.right.bottom.mas_equalTo(0);
        }];
        
        [self.bannerView mas_makeConstraints:^(MASConstraintMaker *make) {
           
            make.left.mas_equalTo(TTScreenWidth);
            make.top.mas_equalTo(0);
            make.width.mas_equalTo(TTScreenWidth);
            make.height.mas_equalTo(self);
        }];
        
    } else {

        [self.bannerView mas_makeConstraints:^(MASConstraintMaker *make) {
           
            make.left.mas_equalTo(0);
            make.top.mas_equalTo(0);
            make.width.mas_equalTo(TTScreenWidth);
            make.height.mas_equalTo(self);
        }];
                
        [self.normalView removeFromSuperview];
    }
    
}

- (SDCycleScrollView *)bannerView {
    if (!_bannerView) {
        _bannerView = [[SDCycleScrollView alloc] init];
        _bannerView.backgroundColor = [UIColor whiteColor];
        _bannerView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
        _bannerView.autoScroll = NO;
        _bannerView.infiniteLoop = NO;
        _bannerView.placeholderImage =[UIImage imageNamed:@"placeholder"];
        _bannerView.delegate = self;
        _bannerView.pageControlStyle = SDCycleScrollViewPageContolStyleClassic;
    }
    return _bannerView;
}

- (UILabel *)pageLabel {
    if (!_pageLabel) {
        _pageLabel = [[UILabel alloc] init];
        _pageLabel.textColor = [UIColor whiteColor];
        _pageLabel.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.3];
        _pageLabel.font = [UIFont systemFontOfSize:11];
        _pageLabel.textAlignment = 1;
        _pageLabel.layer.cornerRadius = 24/2;
        _pageLabel.layer.masksToBounds = YES;
    }
    return _pageLabel;
}

- (UIView *)normalView {
    if (!_normalView) {
        _normalView = [[UIView alloc] init];
        _normalView.backgroundColor = [UIColor blackColor];
    }
    return _normalView;
}

- (TT_AVPlayer *)avPlayer {
    if (!_avPlayer) {
        _avPlayer = [[TT_AVPlayer alloc] init];
    }
    return _avPlayer;
}


@end
